<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
<ui:composition template="template/adminBase.xhtml">

    <ui:define name="adminContent">
        <h:form>
            <h:dataTable value="#{showingController.timeTables}" var="timeTable"
                         styleClass="cinemaTable"
                         headerClass="cinemaTableHeader"
                         rowClasses="cinemaTableOddRow,cinemaTableEvenRow">
                <h:column>
                    <f:facet name="header">Movie</f:facet>
                    <h:selectOneMenu value="#{showingController.editMovieId}"
                                     rendered="#{showingController.canEdit.get(showingController.timeTables.indexOf(timeTable))}"
                                     class="inputText">
                        <f:selectItems value="#{showingController.movies}" var="movie" itemLabel="#{movie.title}" itemValue="#{movie.mId}"/>
                    </h:selectOneMenu>
                    <h:outputText value="#{timeTable.movie.title}"
                                  rendered="#{not showingController.canEdit.get(showingController.timeTables.indexOf(timeTable))}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">Start time</f:facet>
                    <h:inputText class="datepicker" value="#{showingController.editStartTime}"
                                 rendered="#{showingController.canEdit.get(showingController.timeTables.indexOf(timeTable))}">
                        <f:convertDateTime
                                pattern="yyyy/MM/dd HH:mm"/>
                    </h:inputText>
                    <h:outputText value="#{timeTable.startTime}"
                                  rendered="#{not showingController.canEdit.get(showingController.timeTables.indexOf(timeTable))}">
                        <f:convertDateTime
                            pattern="yyyy/MM/dd HH:mm"/>
                    </h:outputText>
                </h:column>
                <h:column>
                    <f:facet name="header">Room</f:facet>
                    <h:selectOneMenu value="#{showingController.editRoomId}"
                                     rendered="#{showingController.canEdit.get(showingController.timeTables.indexOf(timeTable))}"
                                     class="inputText">
                        <f:selectItems value="#{showingController.rooms}" var="room" itemLabel="#{room.name}" itemValue="#{room.roomId}"/>
                    </h:selectOneMenu>
                    <h:outputText value="#{timeTable.room.name}"
                                  rendered="#{not showingController.canEdit.get(showingController.timeTables.indexOf(timeTable))}"/>
                </h:column>
                <h:column>
                    <f:facet name="header">Edit</f:facet>
                    <h:commandButton class="adminButton" value="Edit"
                                     action="#{showingController.editTimeTable}"
                                     rendered="#{not showingController.canEdit.get(showingController.timeTables.indexOf(timeTable))}">
                        <f:setPropertyActionListener
                                target="#{showingController.timeTable}" value="#{timeTable}"/>
                    </h:commandButton>
                    <h:commandButton class="adminButton" value="Save"
                                     action="#{showingController.saveTimeTable}"
                                     rendered="#{showingController.canEdit.get(showingController.timeTables.indexOf(timeTable))}">
                        <f:setPropertyActionListener
                                target="#{showingController.timeTable}" value="#{timeTable}"/>
                    </h:commandButton>
                </h:column>
                <h:column>
                    <f:facet name="header">Delete</f:facet>
                    <h:commandButton class="adminButton" value="Delete"
                                     action="#{showingController.deleteTimeTable}">
                        <f:setPropertyActionListener
                                target="#{showingController.timeTable}" value="#{timeTable}"/>
                    </h:commandButton>
                </h:column>
            </h:dataTable>
        </h:form>
        <h:form>
            <h3>Add Showing</h3>
            <table>
                <tr>
                    <td>Movie:</td>
                    <td>
                        <h:selectOneMenu value="#{showingController.movieId}" class="adminButton">
                            <f:selectItems value="#{showingController.movies}" var="movie"
                                           itemValue="#{movie.mId}" itemLabel="#{movie.title}"/>
                        </h:selectOneMenu>
                    </td>
                </tr>
                <tr>
                    <td>Start Time:</td>
                    <td>
                        <h:inputText id="inputDate" class="datepicker" value="#{showingController.startTime}">
                            <f:validateLength minimum="2"/>
                            <f:convertDateTime
                                    pattern="yyyy/MM/dd HH:mm"/>
                        </h:inputText>
                        <h:message for="inputDate" style="color:red"/>
                    </td>
                </tr>
                <tr>
                    <td>Room:</td>
                    <td>
                        <h:selectOneMenu value="#{showingController.roomId}" class="adminButton">
                            <f:selectItems value="#{showingController.rooms}" var="room"
                                           itemValue="#{room.roomId}" itemLabel="#{room.name}"/>
                        </h:selectOneMenu>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <h:commandButton value="Add Showing" class="adminButton"
                                         action="#{showingController.addTimeTable}"/>
                    </td>
                </tr>
            </table>
        </h:form>
    </ui:define>
</ui:composition>
</html>
